home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 1_2002.ISO / Data / Zips / VB module 186674222001.psc / code.bas next >
Encoding:
BASIC Source File  |  2001-04-20  |  21.8 KB  |  530 lines

  1. Attribute VB_Name = "Declarations"
  2. '====================================
  3. 'ModuleReader Application For Visual Basic classes
  4. '====================================
  5. 'This application will read all VB modules and class
  6. 'modules and derive the names of subs in them.
  7. 'It will list all these items just like the VB IDE.
  8. '====================================
  9. 'By Sushant Pandurangi (sushant@phreaker.net)
  10. '====================================
  11. 'Visit http://sushant.iscool.net for more source,
  12. 'files, tutorials, and the massive VB6LIB with over
  13. '100 functions for your daily programming needs
  14. 'API, strings, network, registry, INI, menus, ...
  15. '====================================
  16. Option Explicit
  17. '====================================
  18. Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
  19. Public Const Keywords = "Public ,Private ,Friend ,Dim ,Sub ,Function , WithEvents , Not , And , Or , Xor ,If , Then ,Do,Loop,Next ,For ,GoTo ,GoSub , As , Long, String, Integer, Variant, Object, Nothing,Else,End,Optional ,UBound,LBound,Mid,CBool,CByte,CStr,CInt,Const , Declare , Lib , Alias ,Set ,On , Error , Resume ,Option , Explicit, Compare ,Option Base 0,Option Base 1, Binary ,Open ,Input , Output ,Print ,Close , Shared , Append ,Read ,Write ,Line ,Type ,Enum ,Attribute ,Let ,Property ,Get ,False,True,ReDim ,ByVal ,End Enum,End Type,End If,Exit ,End Sub,End Function,End With,With ,End Select,Select Case ,Case , Is ,End Property, New "
  20. Public Const EM_UNDO = &HC7
  21. Public Const WM_COPY = &H301
  22. Public Const WM_CUT = &H300
  23. Public Const WM_PASTE = &H302
  24. Public SubCount As Integer
  25. Public FunCount As Integer
  26. Public DefineWhat As String
  27. Public LastItem As Long
  28. Public fMainForm As frmMain
  29. Private Const EM_CHARFROMPOS& = &HD7
  30. Public Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
  31. Public Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long
  32. '====================================
  33. Public Type POINTAPI
  34.         x As Long
  35.         y As Long
  36. End Type
  37. Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
  38.  
  39.  
  40.  
  41. Sub Terminate()
  42. Dim pForm As Form
  43. 'To iterate over
  44.     Unload fMainForm
  45.     'The main form
  46.         For Each pForm In Forms
  47.             Unload pForm
  48.             'Kill it, finish it...
  49.             Set pForm = Nothing
  50.         Next pForm
  51.         'same thing
  52.     '-------------------
  53.     'VB's BEST COMMAND
  54.             End
  55.     'VB's BEST COMMAND
  56.     '-------------------
  57. End Sub
  58.  
  59. Function OpenFile() As Boolean
  60. Dim pF As String
  61. 'FileName to open
  62.     On Error GoTo hell
  63.     'CommonDialog will put up an error on cancelling
  64.         fMainForm.CD1.DialogTitle = "Open file"
  65.         fMainForm.CD1.ShowOpen
  66.         'Show open dialog
  67.         pF = fMainForm.CD1.FileName
  68.         'Load the file
  69.       fMainForm.SB.Panels(2).Text = "Loading...  "
  70.         If fMainForm.CD1.Flags = cdlOFNFileMustExist + cdlOFNPathMustExist + cdlOFNOverwritePrompt + 1 Then
  71.         '6147 I derived as I have put in a few flags on load, they total up
  72.         'to 6146. The ReadOnly is 1, therefore it becomes 6146 + 1= 6147.
  73.             fMainForm.RTF1.Locked = True
  74.             MsgBox "You have chosen to open as read only." & vbNewLine & _
  75.             "You will not be able to edit this module.", vbInformation, "Readonly"
  76.             fMainForm.SB.Panels(3).Text = "READONLY"
  77.         Else
  78.         'If not readonly then don't lock textbox
  79.             fMainForm.RTF1.Locked = False
  80.             fMainForm.SB.Panels(3).Text = ""
  81.         End If
  82.     'Add the functions and subs
  83.       fMainForm.RTF1.LoadFile pF, rtfText
  84.       DoEvents
  85.         With fMainForm.RTF1
  86.         .Visible = False
  87.         .SelStart = 0
  88.         .SelLength = Len(.Text)
  89.         .SelColor = 0
  90.         .SelLength = 0
  91.         .Visible = True
  92.         End With
  93.         AddItems
  94. fMainForm.SB.Panels(1).Text = fMainForm.CD1.FileName
  95. OpenFile = True
  96. Exit Function
  97. hell:
  98. OpenFile = False
  99. 'Error handling
  100. End Function
  101.  
  102. Public Sub AddItems()
  103. Dim pos As Long, TEMP As String, BRPOS As Long, FINAL As String
  104. 'POS    = position of word "function"
  105. 'TEMP  = TEMPorary string to hold ID
  106. 'BRPOS = position of ( symbol from POS
  107. 'FINAL  = FINAL string to add if qualifies
  108.     fMainForm.imSubs.ComboItems.Clear: SubCount = 0: FunCount = 0
  109.     'Clear all things, count should be made 0 now at this time.
  110. Do 'Get stuck in a loop
  111.     pos = InStr(pos + 1, fMainForm.RTF1.Text, "Function ")
  112.     'Where is the word "function"
  113.         If pos = 0 Then Exit Do
  114.         'no functions, word not found
  115.             BRPOS = InStr(pos, fMainForm.RTF1.Text, "(")
  116.             'where bracket symbol is after function name
  117.         If BRPOS = 0 Then GoTo looper1
  118.         'no bracket; syntax error
  119.             TEMP = Mid$(fMainForm.RTF1.Text, pos + 9, BRPOS - pos - 9)
  120.             'POS+9 as we dont want to add the word 'function' and
  121.             If Mid(fMainForm.RTF1.Text, pos - 5, 5) = "Exit " Then GoTo looper1
  122.             'BRPOS-POS will give us the identifier name, but we have
  123.             'added 9 here and hence should substract it there.
  124.             'the word 'function ' is 9 characters long, and 'sub ' is 4.
  125.         If InStr(1, TEMP, "Lib") = 0 Then FINAL = TEMP
  126.         'no LIB keyword found, so it is not a declaration
  127.     If FINAL <> "" Then fMainForm.imSubs.ComboItems.Add , LCase(FINAL), FINAL, 12: FunCount = FunCount + 1
  128.     'Unless LIB is found, FINAL will be TEMP, else FINAL will be "". FunCount is # of functions; increase.
  129. looper1:
  130. Loop
  131. pos = 0: TEMP = "": BRPOS = 0: FINAL = ""
  132. 'OK, now functions have been dealt with.
  133. Do
  134.     'Now the same procedure is followed here, replacing the word
  135.     '"function" with "sub". It looks for subs, adds them, that's it.
  136.     pos = InStr(pos + 1, fMainForm.RTF1.Text, "Sub ")
  137.     'Position of word "Sub"
  138.         If pos = 0 Then Exit Do
  139.         '"Sub" word doesn't exist
  140.             BRPOS = InStr(pos, fMainForm.RTF1.Text, "(")
  141.             'Position of ( symbol
  142.         If BRPOS = 0 Then GoTo looper2
  143.         '"(" doesn't exist
  144.         TEMP = Mid$(fMainForm.RTF1.Text, pos + 4, BRPOS - pos - 4)
  145.             'adjust 4 characters (length of "Sub ")
  146.             If Mid(fMainForm.RTF1.Text, pos - 5, 5) = "Exit " Then GoTo looper2
  147.         If InStr(1, TEMP, "Lib") = 0 Then FINAL = TEMP
  148.         'No LIB keyword is there
  149.     If FINAL <> "" Then fMainForm.imSubs.ComboItems.Add , LCase(FINAL), FINAL, 11: SubCount = SubCount + 1
  150.     'FINAL is not empty; add it to the list and increase the number of subs
  151. looper2:
  152. Loop
  153. pos = 0: TEMP = "": BRPOS = 0: FINAL = ""
  154. 'Clear up the variables
  155. fMainForm.imSubs.Text = SubCount & " Sub(s), " & FunCount & " Function(s)."
  156. 'Show how many functions, and how many subs
  157. fMainForm.SB.Panels(2).Text = " Loaded " & ReadCustomVal("Attribute VB_Name", "module") & ".  "
  158. ListProcs fMainForm.imSubs
  159. 'Regulate the list
  160. End Sub
  161.  
  162. Sub Arrange()
  163. 'Resize controls appropriately
  164. On Error Resume Next
  165.     fMainForm.pM.Width = fMainForm.ScaleWidth
  166.     fMainForm.pM.Height = fMainForm.ScaleHeight - fMainForm.SB.Height - fMainForm.pM.Top
  167.     fMainForm.RTF1.Width = fMainForm.pM.ScaleWidth - fMainForm.RTF1.Left
  168.     fMainForm.RTF1.Height = fMainForm.pM.ScaleHeight
  169.     fMainForm.Ln.Y2 = fMainForm.RTF1.Height
  170.     fMainForm.imSubs.Left = fMainForm.TB.Width - fMainForm.imSubs.Width - ((fMainForm.ScaleWidth - fMainForm.pM.Width) / 2)
  171. End Sub
  172.  
  173. Sub Main()
  174. 'Start up sub
  175.     Set fMainForm = New frmMain
  176.     Load fMainForm
  177.     fMainForm.Show
  178. End Sub
  179.  
  180. Function BrowseColor(pObject As Object) As Long
  181.     'Get the colour from a user
  182.     On Error GoTo hell
  183.         With fMainForm.CD1
  184.             'CommonDialog object
  185.             .Color = pObject.BackColor
  186.             .ShowColor 'Show it
  187.             BrowseColor = .Color
  188.         End With
  189.     Exit Function
  190. hell:
  191.     'return -1 so we can find
  192.     'out that user cancelled.
  193.     BrowseColor = -1
  194. End Function
  195.  
  196. Function ReadValue(Name As String, Optional Default As String, Optional Section As String = "Settings")
  197.     'Function to read values from default filename
  198.     ReadValue = ReadINI(Section, Name, App.Path & "\settings.ini", Default)
  199. End Function
  200.  
  201. Sub SaveValue(Name As String, Value As String, Optional Section As String = "Settings")
  202.     'Function to save values to default filename
  203.     SaveINI Section, Name, Value, App.Path & "\settings.ini"
  204. End Sub
  205.  
  206. Public Function ReadINI(Section As String, Key As String, FileName As String, Optional Default As String)
  207.     'Read from INI file
  208.     Dim sReturn As String
  209.     sReturn = String(255, Chr(0))
  210.     ReadINI = Left(sReturn, GetPrivateProfileString(Section, Key, Default, sReturn, Len(sReturn), FileName))
  211. End Function
  212.  
  213. Public Sub SaveINI(Section As String, Key As String, Value As String, FileName As String)
  214.     'Write to INI file
  215.     WritePrivateProfileString Section, Key, Value, FileName
  216. End Sub
  217.  
  218. Function CBin(Expression As Boolean) As Integer
  219. 'Converts boolean to 0 or 1 in binary
  220. If Expression = True Then CBin = 1 Else CBin = 0
  221. End Function
  222.  
  223. Sub Define(TextBox As Object)
  224. On Error Resume Next
  225. If DefineWhat = "" Then GoTo ERRORS
  226. 'This function should attempt to get the selected
  227. 'word, then go to its definition if the same exists
  228. 'in the curent file which is being viewed or edited.
  229. DefineWhat = "Sub " & DefineWhat
  230. 'add sub to the beginning
  231. If fMainForm.RTF1.Find(DefineWhat) > 0 Then GoTo SF
  232. 'make it function instead of sub
  233. DefineWhat = "Function " & Right(DefineWhat, Len(DefineWhat) - Len("Sub "))
  234. If fMainForm.RTF1.Find(DefineWhat) > 0 Then GoTo SF
  235. 'make it public
  236. DefineWhat = "Public " & Right(DefineWhat, Len(DefineWhat) - Len("Function "))
  237. If fMainForm.RTF1.Find(DefineWhat) > 0 Then GoTo SF
  238. 'make it private
  239. DefineWhat = "Private " & Right(DefineWhat, Len(DefineWhat) - Len("Public "))
  240. If fMainForm.RTF1.Find(DefineWhat) > 0 Then GoTo SF
  241. 'make it dim
  242. DefineWhat = "Dim " & Right(DefineWhat, Len(DefineWhat) - Len("Private "))
  243. If fMainForm.RTF1.Find(DefineWhat) > 0 Then GoTo SF
  244. 'make it withevents
  245. DefineWhat = "WithEvents " & Right(DefineWhat, Len(DefineWhat) - Len("Dim "))
  246. If fMainForm.RTF1.Find(DefineWhat) > 0 Then GoTo SF
  247. 'make it static
  248. DefineWhat = "Static " & Right(DefineWhat, Len(DefineWhat) - Len("WithEvents "))
  249. If fMainForm.RTF1.Find(DefineWhat) > 0 Then GoTo SF
  250. 'make it property
  251. DefineWhat = "Property " & Right(DefineWhat, Len(DefineWhat) - Len("Static "))
  252. If fMainForm.RTF1.Find(DefineWhat) > 0 Then GoTo SF
  253. 'make it byval
  254. DefineWhat = "ByVal " & Right(DefineWhat, Len(DefineWhat) - Len("Property "))
  255. If fMainForm.RTF1.Find(DefineWhat) > 0 Then GoTo SF
  256. 'make it ,
  257. DefineWhat = ", " & Right(DefineWhat, Len(DefineWhat) - Len("ByVal "))
  258. If fMainForm.RTF1.Find(DefineWhat) > 0 Then GoTo SF
  259. 'make it const
  260. DefineWhat = "Const " & Right(DefineWhat, Len(DefineWhat) - Len(", "))
  261. If fMainForm.RTF1.Find(DefineWhat) > 0 Then GoTo SF
  262. 'make it optional
  263. DefineWhat = "Optional " & Right(DefineWhat, Len(DefineWhat) - Len("Const "))
  264. If fMainForm.RTF1.Find(DefineWhat) > 0 Then GoTo SF
  265. 'make it =
  266. DefineWhat = Right(DefineWhat, Len(DefineWhat) - Len("Optional ")) & " = "
  267. If fMainForm.RTF1.Find(DefineWhat) > 0 Then GoTo SF
  268. 'make it (
  269. DefineWhat = "(" & Left(DefineWhat, Len(DefineWhat) - Len(" = "))
  270. If fMainForm.RTF1.Find(DefineWhat) > 0 Then GoTo SF Else GoTo ERRORS
  271. 'if its found then good else tell user that its not there
  272. SF:
  273. 'got it
  274. fMainForm.RTF1.SetFocus
  275. Exit Sub
  276. ERRORS:
  277. 'remove function or sub or whatever
  278. If Left(DefineWhat, 9) = "Function " Then
  279. DefineWhat = Right(DefineWhat, Len(DefineWhat) - Len("Function "))
  280. ElseIf Left(DefineWhat, 4) = "Sub " Then
  281. DefineWhat = Right(DefineWhat, Len(DefineWhat) - Len("Sub "))
  282. ElseIf Left(DefineWhat, 4) = "Dim " Then
  283. DefineWhat = Right(DefineWhat, Len(DefineWhat) - Len("Dim "))
  284. ElseIf Left(DefineWhat, 11) = "WithEvents " Then
  285. DefineWhat = Right(DefineWhat, Len(DefineWhat) - Len("WithEvents "))
  286. ElseIf Left(DefineWhat, 7) = "Static " Then
  287. DefineWhat = Right(DefineWhat, Len(DefineWhat) - Len("Static "))
  288. ElseIf Left(DefineWhat, 9) = "Property " Then
  289. DefineWhat = Right(DefineWhat, Len(DefineWhat) - Len("Property "))
  290. ElseIf Left(DefineWhat, 7) = "Public " Then
  291. DefineWhat = Right(DefineWhat, Len(DefineWhat) - Len("Public "))
  292. ElseIf Left(DefineWhat, 8) = "Private " Then
  293. DefineWhat = Right(DefineWhat, Len(DefineWhat) - Len("Private "))
  294. ElseIf Left(DefineWhat, 1) = "(" Then
  295. DefineWhat = Right(DefineWhat, Len(DefineWhat) - Len("("))
  296. ElseIf Left(DefineWhat, 6) = "ByVal " Then
  297. DefineWhat = Right(DefineWhat, Len(DefineWhat) - Len("ByVal "))
  298. ElseIf Left(DefineWhat, 2) = ", " Then
  299. DefineWhat = Right(DefineWhat, Len(DefineWhat) - Len(", "))
  300. ElseIf Left(DefineWhat, 6) = "Const " Then
  301. DefineWhat = Right(DefineWhat, Len(DefineWhat) - Len("Const "))
  302. ElseIf Left(DefineWhat, 9) = "Optional " Then
  303. DefineWhat = Right(DefineWhat, Len(DefineWhat) - Len("Optional "))
  304. ElseIf Right(DefineWhat, 3) = " = " Then
  305. DefineWhat = Left(DefineWhat, Len(DefineWhat) - Len(" = "))
  306. End If
  307. 'tell the user
  308. MsgBox "The identifier '" & DefineWhat & "' is unrecognized." & vbNewLine & "Make sure such declaration exists.", vbExclamation, "Not found"
  309. End Sub
  310.  
  311. Function ListProcs(List As ImageCombo)
  312. Dim F As Integer, TEMP As Integer, Strin As String
  313. 'For loop
  314. For F = 1 To List.ComboItems.Count
  315. 'variable
  316. Strin = List.ComboItems.Item(F).Text
  317. Do 'and keep doing
  318.     TEMP = InStr(1, List.ComboItems.Item(F).Text, "Private ")
  319.     'position of private
  320.     If TEMP > 0 Then
  321.     Mid$(Strin, TEMP, 8) = Space(8)
  322.     'replace with space so we can trim later,8 is len of 'private '
  323.     Else
  324.     Exit Do
  325.     'it isnt there, proceed
  326.     End If
  327.         TEMP = InStr(1, List.ComboItems.Item(F).Text, "Public ")
  328.         'position of public
  329.         If TEMP > 0 Then
  330.         Mid$(Strin, TEMP, 7) = Space(7)
  331.         'replace with spaces, 7 is len of 'Public '
  332.         Else
  333.         Exit Do
  334.         'not found, proceed
  335.         End If
  336.             TEMP = InStr(1, List.ComboItems.Item(F).Text, "Sub ")
  337.             'find the word 'sub '
  338.             If TEMP > 0 Then
  339.             Mid$(Strin, TEMP, 4) = Space(4)
  340.             'replace spaces, again 4 is len of 'Sub '
  341.             Else
  342.             Exit Do
  343.             'not found then proceed
  344.             End If
  345.         TEMP = InStr(1, List.ComboItems.Item(F).Text, "Function ")
  346.         'word 'Function '
  347.         If TEMP > 0 Then
  348.         Mid$(Strin, TEMP, 9) = Space(9)
  349.         'equal no. of spaces
  350.         Else
  351.         Exit Do
  352.         'not found
  353.         End If
  354.     TEMP = InStr(1, List.ComboItems.Item(F).Text, "Friend ")
  355.     'generally unused friend keyword
  356.     If TEMP > 0 Then
  357.     Mid$(Strin, TEMP, 7) = Space(7)
  358.     'replace spaces
  359.     Else
  360.     Exit Do
  361.     'get out
  362.     End If
  363. Loop
  364. 'keep doing until some Exit Do works
  365. If InStr(1, List.ComboItems(F).Text, Chr(13)) > 0 Then List.ComboItems.Remove F: If List.ComboItems.Item(F).Image = 11 Then SubCount = SubCount - 1 Else FunCount = FunCount - 1
  366. 'contains carriage return; remove this junk item
  367. If InStr(1, List.ComboItems(F).Text, Chr(10)) > 0 Then List.ComboItems.Remove F: If List.ComboItems.Item(F).Image = 11 Then SubCount = SubCount - 1 Else FunCount = FunCount - 1
  368. 'contains linefeed; remove this junk item
  369. If InStr(1, List.ComboItems(F).Text, vbCrLf) > 0 Then List.ComboItems.Remove F: If List.ComboItems.Item(F).Image = 11 Then SubCount = SubCount - 1 Else FunCount = FunCount - 1
  370. 'contains CrLf; remove this junk item
  371. If InStr(1, List.ComboItems(F).Text, ",") > 0 Then List.ComboItems.Remove F: If List.ComboItems.Item(F).Image = 11 Then SubCount = SubCount - 1 Else FunCount = FunCount - 1
  372. 'contains comma; remove this junk item
  373. If InStr(1, List.ComboItems(F).Text, "=") > 0 Then List.ComboItems.Remove F: If List.ComboItems.Item(F).Image = 11 Then SubCount = SubCount - 1 Else FunCount = FunCount - 1
  374. 'contains comma; remove this junk item
  375. If InStr(1, List.ComboItems(F).Text, vbNewLine) > 0 Then List.ComboItems.Remove F: If List.ComboItems.Item(F).Image = 11 Then SubCount = SubCount - 1 Else FunCount = FunCount - 1
  376. 'contains comma; remove this junk item
  377. 'STRIN is the thing that has been spruced up
  378. List.ComboItems.Item(F).Text = Strin
  379. 'trim it, we have replaced certain words with spaces
  380. List.ComboItems.Item(F).Text = Trim(List.ComboItems.Item(F).Text)
  381. Next F
  382. List.Text = SubCount & " Sub(s), " & FunCount & " Function(s)."
  383. End Function
  384.  
  385. Public Function RichWordOver(rch As RichTextBox, x As Single, y As Single) As String
  386. Dim pt As POINTAPI
  387. Dim pos As Long
  388. Dim start_pos As Long
  389. Dim end_pos As Long
  390. Dim ch As String
  391. Dim txt As String
  392. Dim txtlen As Long
  393.     ' Convert the position to pixels.
  394.     pt.x = x \ Screen.TwipsPerPixelX
  395.     pt.y = y \ Screen.TwipsPerPixelY
  396.     ' Get the character number
  397.     pos = SendMessage(rch.hwnd, EM_CHARFROMPOS, 0&, pt)
  398.     If pos <= 0 Then Exit Function
  399.     ' Find the start of the word.
  400.     txt = rch.Text
  401.     For start_pos = pos To 1 Step -1
  402.         ch = Mid$(rch.Text, start_pos, 1)
  403.         ' Allow digits, letters, and underscores, $ and %.
  404.         If Not ((ch >= "0" And ch <= "9") Or (ch >= "a" And ch <= "z") Or (ch >= "A" And ch <= "Z") Or ch = "_" Or ch = "$" Or ch = "%") Then Exit For
  405.     Next start_pos
  406.     start_pos = start_pos + 1
  407.     ' Find the end of the word.
  408.     txtlen = Len(txt)
  409.     For end_pos = pos To txtlen
  410.         ch = Mid$(txt, end_pos, 1)
  411.         ' Allow digits, letters, and underscores.
  412.         If Not ( _
  413.             (ch >= "0" And ch <= "9") Or _
  414.             (ch >= "a" And ch <= "z") Or _
  415.             (ch >= "A" And ch <= "Z") Or _
  416.             ch = "_" _
  417.         ) Then Exit For
  418.     Next end_pos
  419.     end_pos = end_pos - 1
  420.     If start_pos <= end_pos Then _
  421.         RichWordOver = Mid$(txt, start_pos, end_pos - start_pos + 1)
  422. End Function
  423.  
  424. Function ReadCustomVal(sValueName As String, Optional sDefault As String)
  425. On Error Resume Next
  426. Dim pos, pos1, pos2
  427. With fMainForm.RTF1
  428. pos = InStr(1, .Text, sValueName) - Len(sValueName)
  429. If pos = 0 Then ReadCustomVal = sDefault: Exit Function
  430. pos = pos + Len(sValueName)
  431. 'where is svaluename, also we need to go ahead of it
  432. pos1 = InStr(pos, .Text, "=") + 3
  433. If pos = 0 Then ReadCustomVal = sDefault: Exit Function
  434. 'where is = symbol; 3 as there is a " " and quote after it, skip them
  435. pos2 = InStr(pos1, .Text, vbNewLine)
  436. If pos = 0 Then ReadCustomVal = sDefault: Exit Function
  437. 'where is end of line
  438. ReadCustomVal = Mid(.Text, pos1, pos2 - pos1 - 1)
  439. 'we start from pos1, go upto pos2-pos1 and there's a chr(34)
  440. 'at the end which should be removed
  441. End With
  442. End Function
  443.  
  444. Function GetDesc(Text As String) As String
  445. Dim TEMP As String
  446. TEMP = ReadCustomVal("Attribute " & Text & ".VB_Description", "")
  447. GetDesc = TEMP
  448. End Function
  449.  
  450. Sub ColorCode(StringList As String, Colour As Long)
  451. fMainForm.RTF1.Visible = False
  452. Screen.MousePointer = 11
  453. fMainForm.SB.Panels(2).Text = " Loading..."
  454. Dim StrSplitted() As String, pos As Long, i As Long
  455. SplitStr StringList, StrSplitted, ","
  456. For i = 0 To UBound(StrSplitted)
  457. Do
  458. pos = InStr(pos + 1, fMainForm.RTF1.Text, StrSplitted(i))
  459. If pos = 0 Then Exit Do
  460. fMainForm.RTF1.SelStart = pos - 1
  461. fMainForm.RTF1.SelLength = Len(StrSplitted(i))
  462. fMainForm.RTF1.SelColor = Colour
  463. Loop
  464. Next i
  465. fMainForm.RTF1.SelLength = 0
  466. fMainForm.RTF1.Visible = True
  467. fMainForm.RTF1.SelColor = 0
  468. Screen.MousePointer = 0
  469. fMainForm.SB.Panels(2).Text = " Loaded " & ReadCustomVal("Attribute VB_Name", "(module)") & ".  "
  470. End Sub
  471.  
  472. Private Sub SplitStr(strMessage As String, StrLines() As String, Character As String)
  473. 'FUNCTION TO SPLIT STRINGS BY CHARS. FROM PSC.
  474. 'http://www.planet-source-code.com/vb
  475. Dim intAccs As Long
  476. Dim i
  477. Dim lngSpacePos As Long, lngStart As Long
  478.     lngSpacePos = 1
  479.     lngSpacePos = InStr(lngSpacePos, strMessage, Character)
  480.     Do While lngSpacePos
  481.         intAccs = intAccs + 1
  482.         lngSpacePos = InStr(lngSpacePos + 1, strMessage, Character)
  483.     Loop
  484.     ReDim StrLines(intAccs)
  485.     lngStart = 1
  486.     For i = 0 To intAccs
  487.         lngSpacePos = InStr(lngStart, strMessage, Character)
  488.         If lngSpacePos Then
  489.             StrLines(i) = Mid(strMessage, lngStart, lngSpacePos - lngStart)
  490.             lngStart = lngSpacePos + Len(Character)
  491.         Else
  492.             StrLines(i) = Right(strMessage, Len(strMessage) - lngStart + 1)
  493.         End If
  494.     Next
  495. End Sub
  496.  
  497. Sub ColorComments(Optional Colour As Long = &H80&)
  498. fMainForm.RTF1.Visible = False
  499. fMainForm.SB.Panels(2).Text = "Loading...  "
  500. Screen.MousePointer = 11
  501. Dim Sentences() As String, i As Integer, pos As Long, pos2 As Long
  502. SplitStr fMainForm.RTF1.Text, Sentences, vbNewLine
  503. For i = 0 To UBound(Sentences)
  504.     If Left(Trim(Sentences(i)), 1) = "'" Then
  505.         Do
  506.             pos = InStr(pos + 1, fMainForm.RTF1.Text, Sentences(i))
  507.             If pos = 0 Then Exit Do
  508.             fMainForm.RTF1.SelStart = pos - 1
  509.             fMainForm.RTF1.SelLength = Len(Sentences(i))
  510.             fMainForm.RTF1.SelColor = Colour
  511.         Loop
  512.     End If
  513.         Do
  514.             pos = InStr(1, Trim(Sentences(i)), "'")
  515.             If pos = 0 Then Exit Do
  516.             pos2 = InStr(pos + 1, Sentences(i), Chr(13))
  517.             If pos2 = 0 Then Exit Do
  518.             fMainForm.RTF1.SelStart = pos2
  519.             fMainForm.RTF1.SelLength = Len(Sentences(i)) - pos
  520.             fMainForm.RTF1.SelColor = Colour
  521.         Loop
  522. Next i
  523. fMainForm.RTF1.SelLength = 0
  524. fMainForm.RTF1.SelColor = 0
  525. fMainForm.RTF1.Visible = True
  526. fMainForm.SB.Panels(2).Text = " Loaded " & ReadCustomVal("Attribute VB_Name", "") & ".  "
  527. Screen.MousePointer = 0
  528. End Sub
  529.  
  530.